/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ResultEditor.PopUp;

import ResultEditor.Annotations.Annotation;
import ResultEditor.Annotations.Depot;
import ResultEditor.Annotations.suggestion;
import UserInterface.GUI.spanedittype;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.border.BevelBorder;

/**
 * This class will pull up a pop up menu to resolve class conflicts
 *
 * @author Kyle & Chris
 */
public class rightClickOnAnnotPopUp extends JPanel
{
    //Member variables
    protected javax.swing.JComponent theList;
    protected JPopupMenu popup;
    protected UserInterface.GUI eHOST_GUI;

    /**
     * Constructor
     * @param tc - the jList that is being used to display the classConflicts
     * @param eHOST_GUI - The Main GUI
     */
    public rightClickOnAnnotPopUp(javax.swing.JComponent tc, UserInterface.GUI eHOST_GUI)
    {
        this.eHOST_GUI = eHOST_GUI;
        theList = tc;
    }

    /**
     * This method will display the pop up menu at the given coordinates.
     * @param x
     * @param y
     */
    public void pop(final Annotation toUse, int x, int y)
    {
        //The popup menu
        popup = new JPopupMenu();

        JMenuItem item;
        ResultEditor.AnnotationClasses.Depot depot = new ResultEditor.AnnotationClasses.Depot();
        for (suggestion suggested : toUse.verifierFound)
        {
            //Add the new class and position it.
            popup.add(item = new JMenuItem(suggested.toString()));
            item.setHorizontalTextPosition(JMenuItem.RIGHT);

            //Remember the class name.
            final suggestion toChangeTo = suggested;

            //Add a listener for each class that will be called if it is selected.
            item.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent event)
                {
                    //Change the annotation to the suggestion
                    eHOST_GUI.changeAnnotationToSuggestion(toUse, toChangeTo);
                }
            });

        }
        popup.add(item = new JMenuItem("Delete"));

        item.setHorizontalTextPosition(JMenuItem.RIGHT);

            //Add a listener for each class that will be called if it is selected.
            item.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent event)
                {
                    //Delete the Annotation
                    Depot depot = new Depot();
                    //depot.deleteAnnotation(toUse);
                    eHOST_GUI.spanEdit(spanedittype.delete);
                }
            });

        //Show the pop up menu at the passed in position.
        popup.setLabel("Justification");
        popup.setBorder(new BevelBorder(BevelBorder.RAISED));
        popup.show(theList, x, y);

    }
}
